from typing import *


class Solution:
    def threeEqualParts(self, arr: List[int]) -> List[int]:
        oneCount = arr.count(1)
        if oneCount % 3 != 0:
            return [-1, -1]
        if oneCount == 0:
            return [0, 2]
        averageOneCount = oneCount / 3
        firstOneThirdStart = arr.index(1)
        secondOneThirdStart = thirdOneThirdStart = 0
        curOneCount = 0
        for i in range(firstOneThirdStart + 1, len(arr)):
            if arr[i] == 1:
                curOneCount += 1
                if curOneCount == averageOneCount:
                    secondOneThirdStart = i
                    break
        curOneCount = 0
        for i in range(secondOneThirdStart + 1, len(arr)):
            if arr[i] == 1:
                curOneCount += 1
                if curOneCount == averageOneCount:
                    thirdOneThirdStart = i
                    break
        eachLen = len(arr) - thirdOneThirdStart
        if not (firstOneThirdStart + eachLen <= secondOneThirdStart and secondOneThirdStart + eachLen <= thirdOneThirdStart):
            return [-1, -1]
        if all((arr[firstOneThirdStart + i] == arr[secondOneThirdStart + i]
                and arr[secondOneThirdStart + i] == arr[thirdOneThirdStart + i]
                for i in range(eachLen))):
            return [firstOneThirdStart + eachLen - 1, secondOneThirdStart + eachLen]
        else:
            return [-1, -1]
